package com.logistics.web;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.logistics.Shop;
import com.logistics.admin.BaseAction;
import com.logistics.service.ShopService;

@Component("shopAction")
@Scope("prototype")
public class ShopAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public ShopService service;

	@Autowired
	public void setService(ShopService service) {
		this.service = service;
	}

	private List<Shop> shops;
	
	public List<Shop> getShops() {
		return shops;
	}

	public void setShops(List<Shop> shops) {
		this.shops = shops;
	}
	
	private Shop shop;

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public String list() {
		shops = service.query(null);
		return LIST;
	}
	
	public String detail() {
		shop = service.getById(getId());
		
		return SUCCESS;
	}
	
	public String getShopImage(String name) {
		if (StringUtils.isEmpty(name)) {
			return null;
		}
		
		return getImageURl(Shop.SHOP_FOLDER, name);
	}
}
